<?php
    include_once("../action/checkAuthenticationAction.php");
    include_once("../service/articleService.php");
    include_once("../util/constant.php");
    include_once("../util/message.php");
    
    include_once("../util/authUtil.php");
    $perm_array = $_SESSION["permissions"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<title>Chi tiết nhóm trang</title>
	<?php include("import-css.php");?>
</head>
<body>
	<?php include("header.php");?>
    
    <div class="container-fluid">
		<div class="row-fluid">
            <!--Menu-->
            <?php include("menu.php");?>
            <?php
                $action = isset($_GET["action"]) ? $_GET["action"] : NEW_ACTION;
                if($action == EDIT_ACTION){
                    $page_id = $_GET["id"];
                    $page = getPage($page_id);
                }
            ?>
            <!--Content-->
            <div class="box span10 offset2">
                <div class="box-content">
                <?php
                if(!authUtil(array("edit page","create page","view page"),$perm_array,false)){
                    echo "<script>window.location.href='../admin/index.php';</script>";
                }
                $require_perm = array("edit page","create page");
                ?>
                    <form class="form-horizontal" method="POST" action="<?php if(authUtil($require_perm,$perm_array,false)){echo (($action == NEW_ACTION) ? "../action/newPageAction.php" : "../action/editPageAction.php");}?>" id="new_page_form">
                        <div class="control-group">
                            <label for="pageTitle" class="control-label">Nhóm trang</label>
                            <div class="controls">
                                <input required type="text" value="<?php echo ($action == EDIT_ACTION ?  $page["PAG_NAME"] : ""); ?>" id="pageTitle" name="pageTitle" class="input-xlarge focused">
                            </div>
                        </div>
                        
                        <div class="control-group">
                            <label class="control-label" for="selectError">Order</label>
                            <div class="controls">
                                 <select id="order" name="order">
                                    <option value=''>----------</option>
                                    <?php
                                        for($i=1; $i < 21; $i++){
                                    ?>
                                        <option 
                                        <?php
                                            if(isset($page["PAG_ORDER"]))
                                                echo $page["PAG_ORDER"]==$i?'selected':'' ?> value='<?php echo $i; ?>
                                        '>
                                            <?php echo $i; ?>
                                        </option>
                                    <?php        
                                        }
                                    ?>
                                 </select>
                            </div>
                        </div>
                        <?php 
                            if(authUtil($require_perm,$perm_array,false)){
                        ?>
                            <center>
                                <button type="submit" class="btn btn-primary"><?php echo (($action == NEW_ACTION) ? "Tạo mới" : "Cập nhật"); ?></button>
                            </center>
                        <?php
                            }
                        ?>
                        <input type="hidden" name="edit_page_id" id="edit_page_id" value="<?php echo isset($page["PAG_ID"])?$page["PAG_ID"]:"0"; ?>"/>
                    </form>
                </div>
                
            </div><!--/span-->
        </div>
    </div>

    <?php include("footer.php");?>
		
	</div><!--/.fluid-container-->

	<?php include("import-js.php");?>	
</body>
</html>

